
class List_dict(dict):
    '''
    This is a dictionary that works like normal, except if you try to assign
        again to the same key it starts a list and appends to it on subsequent
        assignments to that same key.
    example:
        l = List_dict()
        l[1] = 1
        print l[1]
        >>> 1
        l[1] = 2
        print l[1]
        >>> [1,2]

    WARNING:
        undesirable behavior results if lists are assigned, for example:
            l = List_dict()
            l[1] = [1,2,3]
            l[1] = [4,5,6]
            print l[1]
            >>> [1,2,3,[4,5,6]]
    '''
    def __setitem__(self, key, value):
        try:
            old_value = self[key]
            if type(old_value) == list:
                old_value.append(value)
            else:
                old_value = [old_value, value]
            dict.__setitem__(self,key,old_value)
        except KeyError:
            dict.__setitem__(self, key, value)
        
            
